<%@ page import="com.fjrcloud.entity.Land" %>
<%@ page import="com.fjrcloud.entity.PriceType" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">


    <title>单价设置</title>

    <link rel="shortcut icon" href="favicon.ico">
    <link href="${path}/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="${path}/css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="${path}/css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="${path}/css/animate.css" rel="stylesheet">
    <link href="${path}/css/style.css?v=4.1.0" rel="stylesheet">

    <style>
        .complete {
            background-color: #1ab394;
            color: #FFFFFF;
        }
        .incomplete {
            background-color: #f8ac59;
            color: #FFFFFF;
        }
    </style>
</head>

<body class="gray-bg">

    <div class="wrapper wrapper-content">
        <div class="row">
            <div class="col-sm-12 animated fadeInRight">

                <div class="ibox">
                    <div class="ibox-title">
                        <h5>单价管理</h5>
                    </div>
                    <div class="ibox-content">

                        <div class="project-list">

                            <table class="table table-hover">
                                <tbody>
                                    <c:set var="relocation" value="<%=PriceType.relocation %>"/>
                                    <tr data-class="${relocation}" data-unit="${relocation.unit}">
                                        <td class="project-title"><span>${relocation.label }</span></td>
                                        <td class="project-completion"><small><c:if test="${not empty relocationPrice}">${relocationPrice.price }/${relocation.unit}</c:if></small></td>
                                        <td class="project-actions">
                                            <a href="#" class="btn btn-white btn-sm update"><i class="fa fa-pencil"></i> 编辑 </a>
                                        </td>
                                    </tr>
                                    <c:set var="temporary" value="<%=PriceType.temporary %>"/>
                                    <tr data-class="${temporary}" data-unit="${temporary.unit}">
                                        <td class="project-title"><span>${temporary.label }</span></td>
                                        <td class="project-completion"><small><c:if test="${not empty temporaryPrice}">${temporaryPrice.price }/${temporary.unit}</c:if></small></td>
                                        <td class="project-actions">
                                            <a href="#" class="btn btn-white btn-sm update"><i class="fa fa-pencil"></i> 编辑 </a>
                                        </td>
                                    </tr>
                                    <c:set var="difficult" value="<%=PriceType.difficult %>"/>
                                    <tr data-class="${difficult}" data-unit="${difficult.unit}">
                                        <td class="project-title"><span>${difficult.label }</span></td>
                                        <td class="project-completion"><small><c:if test="${not empty difficultPrice}">${difficultPrice.price }/${difficult.unit}</c:if></small></td>
                                        <td class="project-actions">
                                            <a href="#" class="btn btn-white btn-sm update"><i class="fa fa-pencil"></i> 编辑 </a>
                                        </td>
                                    </tr>
                                    <c:set var="landReward" value="<%=PriceType.landReward %>"/>
                                    <tr data-class="${landReward}" data-unit="${landReward.unit}">
                                        <td class="project-title"><span>${landReward.label }</span></td>
                                        <td class="project-completion"><small><c:if test="${not empty landRewardPrice}">${landRewardPrice.price }/${landReward.unit}</c:if></small></td>
                                        <td class="project-actions">
                                            <a href="#" class="btn btn-white btn-sm update"><i class="fa fa-pencil"></i> 编辑 </a>
                                        </td>
                                    </tr>
                                    <c:set var="signingReward" value="<%=PriceType.signingReward %>"/>
                                    <tr data-class="${signingReward}" data-unit="${signingReward.unit}">
                                        <td class="project-title"><span>${signingReward.label }</span></td>
                                        <td class="project-completion"><small><c:if test="${not empty signingRewardPrice}">${signingRewardPrice.price }/${signingReward.unit}</c:if></small></td>
                                        <td class="project-actions">
                                            <a href="#" class="btn btn-white btn-sm update"><i class="fa fa-pencil"></i> 编辑 </a>
                                        </td>
                                    </tr>
                                    <c:set var="sealReward" value="<%=PriceType.sealReward %>"/>
                                    <tr data-class="${sealReward}" data-unit="${sealReward.unit}">
                                        <td class="project-title"><span>${sealReward.label }</span></td>
                                        <td class="project-completion"><small><c:if test="${not empty sealRewardPrice}">${sealRewardPrice.price }/${sealReward.unit}</c:if></small></td>
                                        <td class="project-actions">
                                            <a href="#" class="btn btn-white btn-sm update"><i class="fa fa-pencil"></i> 编辑 </a>
                                        </td>
                                    </tr>

                                    <c:set var="transitionReward" value="<%=PriceType.transitionReward %>"/>
                                    <tr data-class="${transitionReward}" data-unit="${transitionReward.unit}">
                                        <td class="project-title"><span>${transitionReward.label }</span></td>
                                        <td class="project-completion"><small><c:if test="${not empty transitionRewardPrice}">${transitionRewardPrice.price }/${transitionReward.unit}</c:if></small></td>
                                        <td class="project-actions">
                                            <a href="#" class="btn btn-white btn-sm update"><i class="fa fa-pencil"></i> 编辑 </a>
                                        </td>
                                    </tr>

                                    <c:set var="layer4" value="<%=PriceType.layer4 %>"/>
                                    <tr data-class="${layer4}" data-unit="${layer4.unit}">
                                        <td class="project-title"><span>${layer4.label }</span></td>
                                        <td class="project-completion"><small><c:if test="${not empty layer4Price}">${layer4Price.price }/${layer4.unit}</c:if></small></td>
                                        <td class="project-actions">
                                            <a href="#" class="btn btn-white btn-sm update"><i class="fa fa-pencil"></i> 编辑 </a>
                                        </td>
                                    </tr>
                                    <c:set var="layer5" value="<%=PriceType.layer5 %>"/>
                                    <tr data-class="${layer5}" data-unit="${layer5.unit}">
                                        <td class="project-title"><span>${layer5.label }</span></td>
                                        <td class="project-completion"><small><c:if test="${not empty layer5Price}">${layer5Price.price }/${layer5.unit}</c:if></small></td>
                                        <td class="project-actions">
                                            <a href="#" class="btn btn-white btn-sm update"><i class="fa fa-pencil"></i> 编辑 </a>
                                        </td>
                                    </tr>
                                    <c:set var="layer6" value="<%=PriceType.layer6 %>"/>
                                    <tr data-class="${layer6}" data-unit="${layer6.unit}">
                                        <td class="project-title"><span>${layer6.label }</span></td>
                                        <td class="project-completion"><small><c:if test="${not empty layer6Price}">${layer6Price.price }/${layer6.unit}</c:if></small></td>
                                        <td class="project-actions">
                                            <a href="#" class="btn btn-white btn-sm update"><i class="fa fa-pencil"></i> 编辑 </a>
                                        </td>
                                    </tr>
                                    <c:set var="takeCareOfBuy" value="<%=PriceType.takeCareOfBuy %>"/>
                                    <tr data-class="${takeCareOfBuy}" data-unit="${takeCareOfBuy.unit}">
                                        <td class="project-title"><span>${takeCareOfBuy.label }</span></td>
                                        <td class="project-completion"><small><c:if test="${not empty takeCareOfBuyPrice}">${takeCareOfBuyPrice.price }/${takeCareOfBuy.unit}</c:if></small></td>
                                        <td class="project-actions">
                                            <a href="#" class="btn btn-white btn-sm update"><i class="fa fa-pencil"></i> 编辑 </a>
                                        </td>
                                    </tr>
                                    <c:set var="equallyShared" value="<%=PriceType.equallyShared %>"/>
                                    <tr data-class="${equallyShared}" data-unit="${equallyShared.unit}">
                                        <td class="project-title"><span>${equallyShared.label }</span></td>
                                        <td class="project-completion"><small><c:if test="${not empty equallySharedPrice}">${equallySharedPrice.price }/${equallyShared.unit}</c:if></small></td>
                                        <td class="project-actions">
                                            <a href="#" class="btn btn-white btn-sm update"><i class="fa fa-pencil"></i> 编辑 </a>
                                        </td>
                                    </tr>
                                    <c:set var="errorAreaPriceBasic" value="<%=PriceType.errorAreaPriceBasic %>"/>
                                    <tr data-class="${errorAreaPriceBasic}" data-unit="${errorAreaPriceBasic.unit}">
                                        <td class="project-title"><span>${errorAreaPriceBasic.label }</span></td>
                                        <td class="project-completion"><small><c:if test="${not empty errorAreaPriceBasicPrice}">${errorAreaPriceBasicPrice.price }/${errorAreaPriceBasic.unit}</c:if></small></td>
                                        <td class="project-actions">
                                            <a href="#" class="btn btn-white btn-sm update"><i class="fa fa-pencil"></i> 编辑 </a>
                                        </td>
                                    </tr>
                                    <c:set var="errorAreaPriceSecondary" value="<%=PriceType.errorAreaPriceSecondary %>"/>
                                    <tr data-class="${errorAreaPriceSecondary}" data-unit="${errorAreaPriceSecondary.unit}">
                                        <td class="project-title"><span>${errorAreaPriceSecondary.label }</span></td>
                                        <td class="project-completion"><small><c:if test="${not empty errorAreaPriceSecondaryPrice}">${errorAreaPriceSecondaryPrice.price }/${errorAreaPriceSecondary.unit}</c:if></small></td>
                                        <td class="project-actions">
                                            <a href="#" class="btn btn-white btn-sm update"><i class="fa fa-pencil"></i> 编辑 </a>
                                        </td>
                                    </tr>
                                    <c:set var="oldManSubsidies" value="<%=PriceType.oldManSubsidies %>"/>
                                    <tr data-class="${oldManSubsidies}" data-unit="${oldManSubsidies.unit}">
                                        <td class="project-title"><span>${oldManSubsidies.label }</span></td>
                                        <td class="project-completion"><small><c:if test="${not empty oldManSubsidiesPrice}">${oldManSubsidiesPrice.price }/${oldManSubsidies.unit}</c:if></small></td>
                                        <td class="project-actions">
                                            <a href="#" class="btn btn-white btn-sm update"><i class="fa fa-pencil"></i> 编辑 </a>
                                        </td>
                                    </tr>
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- 全局js -->
    <script src="${path}/js/jquery.min.js?v=2.1.4"></script>
    <script src="${path}/js/bootstrap.min.js?v=3.3.6"></script>
    <script src="${path}/js/plugins/layer/layer.min.js"></script>
    <!-- iCheck -->
    <script src="${path}/js/plugins/iCheck/icheck.min.js"></script>
    <!-- 自定义js -->
    <script src="${path}/js/content.js?v=1.0.0"></script>
    <script src="${path}/js/jquery.form.js"></script>


    <script>

        function updateHtml(unit) {
            var html ='\
                    <div class="ibox-content" style="overflow: hidden;height: 100%;">\
                        <form class="form-horizontal" method="post">\
                            <input type="text" name="type" style="display: none;">\
                            <div class="form-group">\
                                <label class="col-sm-2 control-label">单价：</label>\
                                <div class="col-sm-10">\
                                    <div class="input-group">\
                                        <input type="number" min=0 class="form-control" name="price"> <span class="input-group-addon">/'+unit+'</span>\
                                    </div>\
                                </div>\
                            </div>\
                            <div class="form-group">\
                                <label class="col-sm-2 control-label">描述：</label>\
                                <div class="col-sm-10">\
                                    <textarea class="form-control" style="resize:none" name="description"></textarea>\
                                </div>\
                            </div>\
                        </form>\
                    </div>';

            return html;
        }

        $(document).ready(function(){

            $('.update').click(function () {

                var type = $(this).parents('tr').attr('data-class');
                var unit = $(this).parents('tr').attr('data-unit');
                var title = $(this).parents('tr').find('.project-title').text();
                $.post(
                    "${path}/api/price/get",
                    {type:type},
                    function (result) {
                        if (result.code == "${result_success}") {

                            layer.open({
                                title:title,
                                type: 1,
                                area: ['600px','auto'],
                                content: updateHtml(unit),
                                btn:['保存','取消'],
                                success:function (layero, index) {

                                    $(layero).find('input[name="type"]').val(type);
                                    if(result.data != null){
                                        $(layero).find('input[name="price"]').val(result.data.price);
                                        $(layero).find('textarea[name="description"]').val(result.data.description);
                                    }
                                },
                                yes: function(index, layero){

                                    var options ={
                                        type: "post",
                                        url: "${path}/api/price/save",
                                        dataType: "json",
                                        uploadProgress: function (event, position, total, percentComplete) {},
                                        success: function (result) {
                                            if (result.code == "${result_success}") {
                                                location.reload();
                                                layer.close(index);
                                            }else {
                                                layer.msg(result.data);
                                            }
                                        }
                                    };

                                    $(layero).find('form').ajaxSubmit(options);
                                }
                            });
                        }else {
                            layer.msg(result.data);
                        }
                    },
                    'json'
                );
            });

        });

    </script>

    </body>
</html>
